package com.naive.imperative.program.operations;

import java.util.List;

import com.naive.imperative.program.EvaluatableOperation;
import com.naive.imperative.program.ExecutionContext;
import com.naive.imperative.program.Operation;
import com.naive.imperative.program.OperationBlock;


public class ForLoop<T> extends Operation {
	private EvaluatableOperation<List<T>> listClause;
	private OperationBlock block;
	private String name;
	
	@Override
	public void execute(ExecutionContext x) {
		final List<T> list =listClause.evaluate(x);
		x.beforeLoop(this);
		for (T e: list) {
			x.beforeIteration(this);
			x.setVar(name, e);
			block.execute(x);
			x.afterIteration(this);
		}
		x.afterLoop(this);
	}

	public EvaluatableOperation<List<T>> getListClause() {
		return listClause;
	}

	public void setListClause(EvaluatableOperation<List<T>> listClause) {
		this.listClause = listClause;
	}

	public OperationBlock getBlock() {
		return block;
	}

	public void setBlock(OperationBlock block) {
		this.block = block;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
